package com.lzb.randomturntable;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.lzb.randomturntable.databinding.ActivityHomeBinding;
import com.lzb.randomturntable.databinding.FragmentHomeBinding;
import com.lzb.randomturntable.fragment.BombFragment;
import com.lzb.randomturntable.fragment.GuessFragment;
import com.lzb.randomturntable.fragment.HomeFragment;
import com.lzb.randomturntable.fragment.RandomNumberFragment;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class HomeActivity extends BaseTabFragmentHomeActivity<ActivityHomeBinding> {

    @Override
    protected void initView() {
        super.initView();
        mDataBinding.llHomeBottom.setOnClickListener(null);
    }

    @NonNull
    @Override
    protected List<BaseTabFragmentHomeActivity<ActivityHomeBinding>.FragmentViewBinder> getFragmentViewBinders() {
        List<FragmentViewBinder> listFragment = new ArrayList<>();
        listFragment.add(new FragmentViewBinder(HomeFragment.class, R.id.llHome));
        listFragment.add(new FragmentViewBinder(BombFragment.class, R.id.llBomb));
        listFragment.add(new FragmentViewBinder(GuessFragment.class, R.id.llGuess));
        listFragment.add(new FragmentViewBinder(RandomNumberFragment.class, R.id.llRandomNumber));
        return listFragment;
    }


    @Override
    protected void onFragmentViewClick(View view) {
        clearSelection();
        int id = view.getId();
        if (id == R.id.llHome) {
            mDataBinding.ivHome.setImageResource(R.drawable.suijizhuanpan_on);
            mDataBinding.tvHome.setTextColor(Color.parseColor("#FFFFFF"));
        } else if (id == R.id.llBomb) {
            mDataBinding.ivBomb.setImageResource(R.drawable.sheishizhadan_on);
            mDataBinding.tvBomb.setTextColor(Color.parseColor("#FFFFFF"));
        } else if (id == R.id.llGuess) {
            mDataBinding.ivGuess.setImageResource(R.drawable.caizhengfanmian_on);
            mDataBinding.tvGuess.setTextColor(Color.parseColor("#FFFFFF"));
        } else if (id == R.id.llRandomNumber) {
            mDataBinding.ivRandomNumber.setImageResource(R.drawable.bailitiaoyi_on);
            mDataBinding.tvRandomNumber.setTextColor(Color.parseColor("#FFFFFF"));
        }
    }

    @Override
    protected int getFragmentContainerId() {
        return R.id.flContainer;
    }

    @Override
    protected int onCreate() {
        return R.layout.activity_home;
    }


    private void clearSelection() {
        mDataBinding.ivHome.setImageResource(R.drawable.suijizhuanpan_off);
        mDataBinding.tvHome.setTextColor(Color.parseColor("#4DFFFFFF"));
        mDataBinding.ivBomb.setImageResource(R.drawable.sheishizhadan_off);
        mDataBinding.tvBomb.setTextColor(Color.parseColor("#4DFFFFFF"));
        mDataBinding.ivGuess.setImageResource(R.drawable.caizhengfanmian_off);
        mDataBinding.tvGuess.setTextColor(Color.parseColor("#4DFFFFFF"));
        mDataBinding.ivRandomNumber.setImageResource(R.drawable.bailitiaoyi_off);
        mDataBinding.tvRandomNumber.setTextColor(Color.parseColor("#4DFFFFFF"));
    }
}